<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        *{border: 3px solid red}
    </style>
</head>
<body>
<input type="button"value="事件属性绑定"onclick="alert('按钮点击了')">
<input type="button"value="动态绑定"id="btn">
<div onclick="alert('div')">
    <p onclick="alert('p')">
        <input type="button"value="按钮"onclick="alert('按钮')">
    </p>
</div>
<script>
    /*动态绑定:通过js代码给元素添加事件*/
    btn.onclick=function () {
        alert('动态绑定成功!')
    }
</script>
</body>
</html>